<?php
require_once("model/loginBD.php");
function add_invitationBD($mail, $name_contact, $surname_contact) {
	$query = "INSERT INTO invitation (id_contact, mail, name_contact, surname_contact, id_user) 
			  VALUES (NULL, '".$mail."', '".$name_contact."', '".$surname_contact."', '".$_SESSION['id_user']."')";
	logIn();
	$rs = mysql_query($query); //or die('Erreur SQL !'.$query.'<br>'.mysql_error());
	logOut();
	if (!$rs)
		return false;
	return true;
}

function delete_invitation_db($id_contact) {
	$query = "DELETE FROM invitation WHERE (id_contact = '".$id_contact."')";
	logIn();
	mysql_query($query) or die('Erreur SQL !'.$query.'<br>'.mysql_error());
	logOut();
	return true;
}

function view_simple_invitationBD() {
	$query = "SELECT id_contact, name_contact, surname_contact, mail FROM invitation
			  WHERE id_user = '".$_SESSION['id_user']."'"; 
			  
	logIn();
	$result = mysql_query($query) or die('Erreur SQL !'.$query.'<br>'.mysql_error());	
	logOut();
	$total = mysql_num_rows($result);
	if($total) {
		
		while($row = mysql_fetch_array($result)) {
			$tab['id_contact'][] = $row['id_contact'];
			$tab['name_contact'][] = $row['name_contact'];
			$tab['surname_contact'][] = $row['surname_contact'];
			$tab['mail'][] = $row['mail'];
		}
	}
	if( mysql_num_rows($result) > 0) return $tab;	else return 0;
}

function view_invitationBD($id_contact) {
	$query = "SELECT id_contact, name_contact, surname_contact, mail FROM invitation
			  WHERE id_contact = '".$id_contact."'"; 
			  
	logIn();
	$result = mysql_query($query) or die('Erreur SQL !'.$query.'<br>'.mysql_error());	
	logOut();
	$total = mysql_num_rows($result);
	if($total) {
		while($row = mysql_fetch_array($result)) {
			$tab['id_contact'][] = $row['id_contact'];
			$tab['name_contact'][] = $row['name_contact'];
			$tab['surname_contact'][] = $row['surname_contact'];
			$tab['mail'][] = $row['mail'];
		}
	}
	if( mysql_num_rows($result) > 0) return $tab;	else return 0;
}

?>